#pragma once
#include"hash.h"
namespace MoYu
{
	template<class K , class T>
	class unordered_map
	{

	public:
		struct MapOfT
		{
			const K& operator()(const pair<const K, T>& p)
			{
				return p.first;
			}
		};
	private:
		typedef typename HashTable<K, const pair<const K, T>, MapOfT>::Iterator iterator;
		typedef typename HashTable<K, const pair<const K, T>, MapOfT>::Const_Iterator const_iterator;
		HashTable<K , const pair<const K,T> , MapOfT> _ht;

	public:
		iterator begin()
		{
			return _ht.Begin();
		}
		iterator end()
		{
			return _ht.End();
		}

		const_iterator begin() const
		{
			return _ht.Begin();
		}
		const_iterator end() const 
		{
			return _ht.End();
		}

		pair<iterator, bool> insert(const pair<const K, T>& x)
		{
			return _ht.insert(x);
		}

		T& operator[](const K& key)
		{
			pair<iterator,bool> pos = _ht.insert(make_pair(key,T()));
			return pos.second;
		}


		size_t size()
		{
			return _ht.size();
		}

		bool empty()
		{
			return _ht.empty();
		}

		iterator find()
		{
			return _ht.find();
		}


	};

	void test_map()
	{
		MoYu::unordered_map<int , int> st;
		st.insert({1,2});
		st.insert({3,4});
		st.insert({4,5});
		st.insert({2,3});
		for (auto& e : st)
		{
			cout << e.first << " " << e.second << endl;
		}
		cout << endl;
	}
}